package com.roncoo.education.user.service.api;

import com.roncoo.education.course.feign.vo.UserTagNameVO;
import com.roncoo.education.user.common.bo.*;
import com.roncoo.education.util.annotation.RequestRequire;

import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.roncoo.education.user.service.api.biz.ApiUserInfoBiz;
import com.roncoo.education.user.service.dao.impl.mapper.entity.Tzxx;
import com.roncoo.education.user.service.dao.impl.mapper.entity.UserExt;
import com.roncoo.education.user.service.dao.impl.mapper.entity.UserTag;
import com.roncoo.education.user.common.bo.UserAuthBO;
import com.roncoo.education.user.common.bo.UserLoginCodeBO;
import com.roncoo.education.user.common.bo.UserLoginPasswordBO;
import com.roncoo.education.user.common.bo.UserRegisterBO;
import com.roncoo.education.user.common.bo.UserSendCodeBO;
import com.roncoo.education.user.common.bo.auth.UserUpdateBO;
import com.roncoo.education.user.common.dto.TzinfoDTO;
import com.roncoo.education.user.common.dto.UserLoginDTO;
import com.roncoo.education.util.base.BaseController;
import com.roncoo.education.util.base.Page;
import com.roncoo.education.util.base.Result;
import com.taobao.api.ApiException;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;

/**
 * 用户基本信息
 *
 * @author wujing
 */
@RestController
@RequestMapping(value = "/user/api/user")
@Api(tags = "用户基本信息")
public class ApiUserInfoController extends BaseController {

	private static final Class Object = null;
	
	@Autowired
	private ApiUserInfoBiz biz;
	
	/**
	 * 注册接口
	 */
	@ApiOperation(value = "注册接口", notes = "注册成功返回登录信息")
	@RequestMapping(value = "/register", method = RequestMethod.POST)
	public Result<UserLoginDTO> register(@RequestBody UserRegisterBO userRegisterBO) {
		return biz.register(userRegisterBO);
	}

	/**
	 * 用户密码登录接口
	 */
	@ApiOperation(value = "用户密码登录接口", notes = "用户密码登录")
	@RequestMapping(value = "/login/password", method = RequestMethod.POST)
	public Result<UserLoginDTO> loginPassword(@RequestBody UserLoginPasswordBO userLoginPasswordBO) {
		return biz.loginPassword(userLoginPasswordBO);
	}

	/**
	 * 用户验证码登录接口
	 */
	@ApiOperation(value = "用户验证码登录接口", notes = "用户验证码登录")
	@RequestMapping(value = "/login/code", method = RequestMethod.POST)
	public Result<UserLoginDTO> loginCode(@RequestBody UserLoginCodeBO userLoginCodeBO) {
		return biz.loginCode(userLoginCodeBO);
	}

	/**
	 * 验证码发送接口
	 */
	@ApiOperation(value = "验证码发送接口", notes = "发送手机验证码")
	@RequestMapping(value = "/send/code", method = RequestMethod.POST)
	public Result<String> sendCode(@RequestBody UserSendCodeBO userSendCodeBO) {
		return biz.sendCode(userSendCodeBO);
	}

	/**
	 * 授权登录接口
	 */
	@ApiOperation(value = "授权登录接口", notes = "后台登录到讲师中心时使用")
	@RequestMapping(value = "/auth", method = RequestMethod.POST)
	public Result<String> auth(@RequestBody UserAuthBO userAuthBO) {
		return null;
	}


	/**
	 * 钉钉授权登录接口
	 */
	@ApiOperation(value = "钉钉授权登录接口", notes = "钉钉授权登陆")
	@RequestMapping(value = "/dingd/auth", method = RequestMethod.POST)
	@RequestRequire(require = "code",parameter=UserDingdAuthBO.class)
	public Result<UserLoginDTO> dingDAuth(@RequestBody UserDingdAuthBO userAuthBO)throws Exception {
		return biz.dingdAuthLogin(userAuthBO);
	}

	/**
	 * 用户修改密码接口
	 *
	 * @author wuyun
	 */
	@ApiOperation(value = "用户修改密码接口", notes = "用户修改密码接口")
	@RequestMapping(value = "/update/password", method = RequestMethod.POST)
	public Result<Integer> updatePassword(@RequestBody UserUpdateBO userUpdateBO) {
		return biz.updatePassword(userUpdateBO);
	}

	/**
	 * 用户列表/接口 
	 * @param user
	 * @return
	 */
	@ApiOperation(value = "用户列表/接口", notes = "用户列表/接口")
	@RequestMapping(value = "/getUserInfo", method = RequestMethod.POST)
	public Result<Page<UserExt>> userList(@RequestBody UserExtBo userExt){
		return biz.userList(userExt);
	}
	
	/**
	 * 标签和用户关联
	 * @param userExt
	 */
	@ApiOperation(value = "标签和用户关联", notes = "标签和用户关联")
	@RequestMapping(value = "/userTag", method = RequestMethod.POST)
	public Result<Page<UserTag>> userTag(@RequestBody UserTagBo userTag) {
		return biz.getTagNameList(userTag);
	}
	
	@ApiOperation("通知信息接口")
	@PostMapping("/userInfo")
	public Result<HashedMap<String, Object>> userInfo() throws ApiException {
		return biz.userInfo();
	}
	
	@ApiOperation("通知查询接口")
	@PostMapping("/selectUserInfo")
	public Result<ArrayList<TzinfoDTO>> getUserInfo(@RequestBody TzinfoBO tzinfoBO){
		return biz.getUserInfo(tzinfoBO);
	}
	/**
	 * 用户和标签关联API接口
	 * @param token
	 */
	@ApiOperation(value = "用户和标签关联API接口",notes = " 用户和标签关联API接口")
	@RequestMapping(value = "/userLabel/{userNo}", method = RequestMethod.POST)
	public Result<ArrayList<UserTagNameVO>> userLabel(@PathVariable("userNo") Long userNo) {
		return biz.userLabel(userNo);
	}
	
	/**
	 * 新增通知信息
	 * @param addTzInfoBO
	 * @return
	 */
	@ApiOperation("新增通知信息")
	@PostMapping("/addUserInfo")
	public Result<Integer> addUserInfo(@RequestBody AddTzInfoBO addTzInfoBO){
		return biz.addUserInfo(addTzInfoBO);
	}
	
	/**
	 * 通知列表
	 * @param pageHaperBO
	 * @return
	 */
	@ApiOperation("通知列表")
	@PostMapping("/selectTzxx")
	public Result<com.baomidou.mybatisplus.extension.plugins.pagination.Page<Tzxx>> selectTzxx(@RequestBody PageHaperBO pageHaperBO){
		return biz.selectTzxx(pageHaperBO);
	}
	
	/**
	 * 已发送信息查看接口
	 * @param id
	 * @return
	 */
	@ApiOperation("已发送信息查看接口")
	@PostMapping("/selectSendTzxx")
	public Result<Tzxx> selectSendTzxx(Integer id){
		return biz.selectSendTzxx(id);
	}
	
	/**
	 * 定时发送信息编辑接口
	 * @param tzxxDTO
	 * @return
	 */
	@ApiOperation("定时发送信息编辑接口")
	@PostMapping("/editSendTzxx")
	public Result<Integer> editSendTzxx(@RequestBody EditTzInfoBO editTzInfoBO){
		return biz.editSendTzxx(editTzInfoBO);
	}
	
	/**
	 * 删除通知信息接口
	 * @param id
	 * @return
	 */
	@ApiOperation("删除通知信息接口")
	@PostMapping("/delTzInfo")
	public Result<Integer> delTzInfo(Integer id){
		return biz.delTzInfo(id);
	}
}
